package com.lanou3g.mynewstest.module.topic;

import android.content.Context;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.lanou3g.mynewstest.R;
import com.lanou3g.mynewstest.beans.TopicBeans;
import com.lanou3g.mynewstest.tools.CircleImageView;
import com.lanou3g.mynewstest.tools.MyRequestQueue;

/**
 * Created by dllo on 16/1/23.
 */
public class TopicAdapter extends BaseAdapter {
    private Context context;
    private TopicBeans data;


    public TopicAdapter(Context context, TopicBeans data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return null==data.getData().getExpertList()? 0:data.getData().getExpertList().size();
    }

    @Override
    public Object getItem(int position) {
        return data.getData().getExpertList().get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_topic, parent, false);
            holder = new ViewHolder(convertView);
//            convertView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Intent intent=new Intent(context,TopicDetailActivity.class);
//                    intent.putExtra("expertId",data.getData().getExpertList().get(position).getExpertId());
//                    context.startActivity(intent);
//                }
//            });
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.alias.setText(data.getData().getExpertList().get(position).getAlias());
        holder.name.setText(data.getData().getExpertList().get(position).getName());
        holder.classification.setText(data.getData().getExpertList().get(position).getClassification());
        holder.concernCount.setText(""+data.getData().getExpertList().get(position).getConcernCount());
        MyRequestQueue.setNetImage(holder.imageView, data.getData().getExpertList().get(position).getPicurl());
        MyRequestQueue.setNetImage(holder.circleImageView,data.getData().getExpertList().get(position).getHeadpicurl());

        return convertView;
    }

    class ViewHolder {
        NetworkImageView imageView;
        CircleImageView circleImageView;
        TextView alias, name, classification, concernCount;

        public ViewHolder(View view) {
            imageView = (NetworkImageView) view.findViewById(R.id.topic_pic_iv);
            circleImageView = (CircleImageView) view.findViewById(R.id.topic_head_iv);
            alias = (TextView) view.findViewById(R.id.topic_alias_tv);
            name = (TextView) view.findViewById(R.id.topic_name_tv);
            classification = (TextView) view.findViewById(R.id.topic_classification_tv);
            concernCount = (TextView) view.findViewById(R.id.topic_concernCount_tv);

        }
    }
}
